package cn.com.headfree.checkrepeat.dao.impl;

import cn.com.headfree.checkrepeat.dao.CheckRepeatDao;
import cn.com.headfree.checkrepeat.vo.*;
import cn.com.headfree.entity.*;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.common.dto.Page;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("checkRepeatDao")
public class CheckRepeatDaoImpl extends BaseDaoImpl<TEmpBaseInfo> implements CheckRepeatDao {

	@Override
	public void getAcadeAchiveInfoByName(Page<TAcadeAchiveInfoVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_acade_achive_info t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.acad_name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TAcadeAchiveInfoVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}

	@Override
	public void getStandInfoByName(Page<TStandInfoVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_stand_info t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TStandInfoVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}

	@Override
	public void getPatentInfoByName(Page<TPatentInfoVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_patent_info t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.patent_name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TPatentInfoVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}

	@Override
	public void getTecInnovInfoByName(Page<TTecInnovInfoVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_tec_innov_info t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.achi_name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TTecInnovInfoVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}

	@Override
	public void getTecManInnovInfoByName(Page<TTecManInnovVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_tec_man_innov t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.achi_name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TTecManInnovVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}

	@Override
	public void getProjAchieveInfoByName(Page<TProjAchieveInfoVo> page,String name,String orgId) {
		StringBuilder sqlBuilder = new StringBuilder("select s.* from ");
		sqlBuilder.append(" (select t.* from t_proj_achieve_info t where 1=1 ");
		sqlBuilder.append(" and t.del_sign = 0 and t.flow_status <> 2 and t.is_cover <> 1 and t.org_id = ? and t.proj_name LIKE concat('%',?,'%') ESCAPE '/' ");
		ArrayList<Object> arrayList = new ArrayList<Object>();
		arrayList.add(orgId);
		arrayList.add(name);
		sqlBuilder.append(" ORDER BY t.create_time desc,t.update_time desc limit 1000 ) s");
		sqlBuilder.append(" GROUP BY s.primitive_id");
		this.findPageBySql(TProjAchieveInfoVo.class, sqlBuilder.toString(), page, arrayList.toArray());
	}
}
